<?php
/**
 * Created by PhpStorm.
 * User: FDG296
 * Date: 2017/7/10
 * Time: 15:33
 */
namespace common\models;

use Yii;
use yii\db\ActiveRecord;

class CategoryRecommend extends ActiveRecord{
    public static function tableName(){
        return '{{%category_recommend}}';
    }

    //获取分类推荐列表
    public function getRecommendList($cate_id){
        $where = ['use_flg'=>1,'category_id'=>$cate_id];
        $result = $this::find()->where($where)->orderBy('sort asc')->asArray()->all();
        return $result;
    }

    public function getList(){
        $where = ['use_flg'=>1];
        $list = array();
        $result = $this::find()->where($where)->orderBy('sort asc')->asArray()->all();
        if(!empty($result)){
            foreach($result as $value){
                $list[$value['category_id']][] = $value;
            }
        }
        return $list;
    }

    public function getCategory($id){
        $where = ['use_flg'=>1,'id'=>$id];
        $result = $this::find()->where($where)->orderBy('sort asc')->select('category_id')->asArray()->one();
        return $result;
    }
}